<template>
  <div>
    <van-popup :title="title" :show="isShow" position="bottom">
      <van-date-picker
        v-if="type == 0"
        v-model="(currentDate as any)"
        :min="minDate"
        :max="maxDate"
        :columns-type="columnsType"
        @confirm="confirm"
        @cancel="close"
      />
      <van-picker-group
        v-if="type == 1"
        :title="title || '日期选择'"
        :tabs="['选择日期', '选择时间']"
        next-step-text="下一步"
        @confirm="confirm"
        @cancel="close"
      >
        <van-date-picker
          :min="minDate"
          :max="maxDate"
          v-model="(currentDate as any)"
        />
        <van-time-picker v-model="(currentTime as any)" />
      </van-picker-group>
    </van-popup>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { getNowFormatDate, maxDate, minDate } from "@/utils/issues";

const props = withDefaults(
  defineProps<{
    isShow: boolean;
    title?: string;
    type?: number;
    columnsType?: any[];
  }>(),
  {
    isShow: false,
    title: "时间选择",
    type: 0,
    columnsType: ["year", "month", "day"] as any,
  }
);
const currentDate = ref<any>([]);
const currentTime = ref(["00", "00"]);
const emits = defineEmits(["confirm", "close"]);

const confirm = (params: any) => {
  if (props.type == 0) {
    const res = params.selectedValues.join("-");
    emits("confirm", res);
  } else if (props.type == 1) {
    const res =
      params[0].selectedValues.join("-") +
      " " +
      params[1].selectedValues.join(":") +
      ":00";
    emits("confirm", res);
  }
};
const init = () => {
  let res = getNowFormatDate() as any[];
  currentDate.value = props.columnsType?.length == 3 ? res : [res[0]];
  // currentDate.value = [2024, 4, 17];
};
init();
const close = () => {
  emits("close");
};
</script>

<style scoped></style>
